package ee.karileet.ui.catalogue.view;

import java.util.ResourceBundle;

import com.vaadin.addon.touchkit.ui.NavigationButton;
import com.vaadin.addon.touchkit.ui.NavigationButton.NavigationButtonClickEvent;
import com.vaadin.addon.touchkit.ui.NavigationButton.NavigationButtonClickListener;
import com.vaadin.addon.touchkit.ui.NavigationView;
import com.vaadin.addon.touchkit.ui.VerticalComponentGroup;

import ee.karileet.productcatalogue.facade.IClientFacade;
import ee.karileet.productcatalogue.facade.impl.ClientFacade;
import ee.karileet.productcatalogue.model.Group;
import ee.karileet.ui.catalogue.util.Const;
import ee.karileet.ui.catalogue.util.Translations;

@SuppressWarnings("serial")
public class GroupListView extends NavigationView {
	private IClientFacade facade = new ClientFacade();
	
    public GroupListView() {
    	ResourceBundle rb = Translations.get(null, Const.TRANSLATIONS);
        setCaption(rb.getString("categorys"));
        
        final VerticalComponentGroup content = new VerticalComponentGroup();
        NavigationButton button = null;
        for (final Group g : facade.listGroups()) {
			button = new NavigationButton(rb.getString(g.getName()));
	        button.addClickListener(new NavigationButtonClickListener() {
	            @Override
	            public void buttonClick(NavigationButtonClickEvent event) {
	                getNavigationManager().navigateTo(new GroupView(g));                
	            }
	        });
	        content.addComponent(button);
        }
        setContent(content);
    };
}
